package top.sdaily.web.controller.sys;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.sdaily.web.context.ReturnBody;
import top.sdaily.web.model.Province;
import top.sdaily.web.service.ProvinceService;

/**
 * Created by tsujishiki on 2017/2/17.
 */
@RestController
@RequestMapping("/province")
public class ProvinceController {

    @Autowired
    ProvinceService provinceService;

    @GetMapping
    public ReturnBody getProvinces() {
        return ReturnBody.success().setData(provinceService.getAllProvince());
    }

    @GetMapping(value = "/{id}")
    public ReturnBody getProvinceById(@PathVariable String id) {
        return ReturnBody.success().setData(provinceService.getProvinceById(id));
    }

    @PostMapping
    public ReturnBody addProvince(@RequestBody Province province) {
        provinceService.insertProvince(province);
        return ReturnBody.success();
    }

    @PutMapping
    public ReturnBody updateProvince(@RequestBody Province province) {
        provinceService.updateProvince(province);
        return ReturnBody.success();
    }

}
